package com.zyl.blog.common.enums;

import lombok.Getter;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.lang.NonNull;

/**
 * @version v1.0
 * @ProjectName: Personal_Blog_Server
 * @Package: com.zyl.blog.common.enums
 * @ClassName: MessageEnum
 * @Description:
 * @Author FinalFantasy
 * @Date 2025/9/12-08:44
 */
@Getter
public enum MessageEnum {
    // ==================== 1. 公共模块（common） ====================
    // 通用操作
    COMMON_SUCCESS("common.success"),
    COMMON_ERROR("common.error"),
    COMMON_PENDING("common.pending"),
    COMMON_TIMEOUT("common.timeout"),
    COMMON_RETRY("common.retry"),

    // 资源相关
    COMMON_RESOURCE_NOT_FOUND("common.resource.not_found"),
    COMMON_RESOURCE_EXIST("common.resource.exist"),
    COMMON_RESOURCE_FORBIDDEN("common.resource.forbidden"),
    COMMON_RESOURCE_DELETED("common.resource.deleted"),
    COMMON_RESOURCE_LOCKED("common.resource.locked"),

    // 参数校验
    COMMON_PARAM_REQUIRED("common.param.required"),
    COMMON_PARAM_INVALID("common.param.invalid"),
    COMMON_PARAM_MIN("common.param.min"),
    COMMON_PARAM_MAX("common.param.max"),
    COMMON_PARAM_RANGE("common.param.range"),
    COMMON_PARAM_LENGTH("common.param.length"),
    COMMON_PARAM_PATTERN("common.param.pattern"),

    // 权限相关
    COMMON_AUTH_NO_PERMISSION("common.auth.no_permission"),
    COMMON_AUTH_TOKEN_INVALID("common.auth.token_invalid"),
    COMMON_AUTH_TOKEN_EXPIRED("common.auth.token_expired"),
    COMMON_AUTH_LOGIN_REQUIRED("common.auth.login_required"),

    // 系统异常
    COMMON_SYSTEM_BUSY("common.system.busy"),
    COMMON_SYSTEM_ERROR("common.system.error"),
    COMMON_SYSTEM_NOT_SUPPORT("common.system.not_support"),
    COMMON_SYSTEM_DEPENDENCY_FAIL("common.system.dependency_fail"),

    // ==================== 2. 认证模块（auth） ====================
    // 登录相关
    AUTH_LOGIN_SUCCESS("auth.login.success"),
    AUTH_LOGIN_FAILURE("auth.login.failure"),
    AUTH_LOGIN_ACCOUNT_LOCKED("auth.login.account_locked"),
    AUTH_LOGIN_ACCOUNT_DISABLED("auth.login.account_disabled"),
    AUTH_LOGIN_PASSWORD_EXPIRED("auth.login.password_expired"),
    AUTH_LOGIN_IP_LIMIT("auth.login.ip_limit"),
    AUTH_LOGIN_CAPTCHA_ERROR("auth.login.captcha_error"),
    AUTH_LOGIN_CAPTCHA_EXPIRED("auth.login.captcha_expired"),

    // 注册相关
    AUTH_REGISTER_SUCCESS("auth.register.success"),
    AUTH_REGISTER_FAILURE("auth.register.failure"),
    AUTH_REGISTER_USERNAME_EXIST("auth.register.username_exist"),
    AUTH_REGISTER_PHONE_EXIST("auth.register.phone_exist"),
    AUTH_REGISTER_EMAIL_EXIST("auth.register.email_exist"),
    AUTH_REGISTER_PHONE_INVALID("auth.register.phone_invalid"),
    AUTH_REGISTER_EMAIL_INVALID("auth.register.email_invalid"),
    AUTH_REGISTER_PASSWORD_WEAK("auth.register.password_weak"),

    // Token相关
    AUTH_TOKEN_GENERATE_FAIL("auth.token.generate_fail"),
    AUTH_TOKEN_INVALID("auth.token.invalid"),
    AUTH_TOKEN_EXPIRED("auth.token.expired"),
    AUTH_TOKEN_REFRESH_SUCCESS("auth.token.refresh_success"),
    AUTH_TOKEN_REFRESH_FAIL("auth.token.refresh_fail"),

    // 权限相关
    AUTH_PERMISSION_NO_ACCESS("auth.permission.no_access"),
    AUTH_PERMISSION_ROLE_INSUFFICIENT("auth.permission.role_insufficient"),
    AUTH_PERMISSION_DATA_SCOPE_LIMIT("auth.permission.data_scope_limit"),

    // 账号管理
    AUTH_ACCOUNT_ACTIVATE_SUCCESS("auth.account.activate_success"),
    AUTH_ACCOUNT_ACTIVATE_FAIL("auth.account.activate_fail"),
    AUTH_ACCOUNT_DISABLE_SUCCESS("auth.account.disable_success"),
    AUTH_ACCOUNT_ENABLE_SUCCESS("auth.account.enable_success"),
    AUTH_ACCOUNT_RESET_PASSWORD_SUCCESS("auth.account.reset_password_success"),
    AUTH_ACCOUNT_RESET_PASSWORD_FAIL("auth.account.reset_password_fail"),
    AUTH_ACCOUNT_CHANGE_PASSWORD_SUCCESS("auth.account.change_password_success"),
    AUTH_ACCOUNT_CHANGE_PASSWORD_FAIL("auth.account.change_password_fail"),

    // ==================== 3. 任务模块（task） ====================
    // 任务创建
    TASK_CREATE_SUCCESS("task.create.success"),
    TASK_CREATE_FAILURE("task.create.failure"),
    TASK_CREATE_PARAM_ERROR("task.create.param_error"),
    TASK_CREATE_EXCEED_LIMIT("task.create.exceed_limit"),
    TASK_CREATE_DEPENDENCY_MISSING("task.create.dependency_missing"),
    TASK_CREATE_NAME_DUPLICATE("task.create.name_duplicate"),

    // 任务状态
    TASK_STATUS_RUNNING("task.status.running"),
    TASK_STATUS_FINISHED("task.status.finished"),
    TASK_STATUS_FAILED("task.status.failed"),
    TASK_STATUS_CANCELLED("task.status.cancelled"),
    TASK_STATUS_PAUSED("task.status.paused"),
    TASK_STATUS_WAITING("task.status.waiting"),
    TASK_STATUS_TIMEOUT("task.status.timeout"),

    // 任务操作
    TASK_OPERATE_START_SUCCESS("task.operate.start_success"),
    TASK_OPERATE_START_FAIL("task.operate.start_fail"),
    TASK_OPERATE_PAUSE_SUCCESS("task.operate.pause_success"),
    TASK_OPERATE_PAUSE_FAIL("task.operate.pause_fail"),
    TASK_OPERATE_CANCEL_SUCCESS("task.operate.cancel_success"),
    TASK_OPERATE_CANCEL_FAIL("task.operate.cancel_fail"),
    TASK_OPERATE_RETRY_SUCCESS("task.operate.retry_success"),
    TASK_OPERATE_RETRY_FAIL("task.operate.retry_fail"),
    TASK_OPERATE_DELETE_SUCCESS("task.operate.delete_success"),
    TASK_OPERATE_DELETE_FAIL("task.operate.delete_fail"),

    // 任务查询
    TASK_QUERY_NOT_FOUND("task.query.not_found"),
    TASK_QUERY_LIST_EMPTY("task.query.list_empty"),
    TASK_QUERY_FILTER_INVALID("task.query.filter_invalid"),

    // 任务执行
    TASK_EXECUTE_RESOURCE_INSUFFICIENT("task.execute.resource_insufficient"),
    TASK_EXECUTE_DEPENDENCY_FAIL("task.execute.dependency_fail"),
    TASK_EXECUTE_CALLBACK_SUCCESS("task.execute.callback_success"),
    TASK_EXECUTE_CALLBACK_FAIL("task.execute.callback_fail"),

    // ==================== 4. 文件模块（file-processing） ====================
    // 文件上传
    FILE_UPLOAD_SUCCESS("file.upload.success"),
    FILE_UPLOAD_FAILURE("file.upload.failure"),
    FILE_UPLOAD_EMPTY("file.upload.empty"),
    FILE_UPLOAD_FORMAT_NOT_SUPPORT("file.upload.format_not_support"),
    FILE_UPLOAD_SIZE_EXCEED("file.upload.size_exceed"),
    FILE_UPLOAD_DUPLICATE("file.upload.duplicate"),
    FILE_UPLOAD_PART_FAIL("file.upload.part_fail"),
    FILE_UPLOAD_PART_MERGE_FAIL("file.upload.part_merge_fail"),
    FILE_UPLOAD_OVERWRITE_FAIL("file.upload.overwrite_fail"),

    // 文件下载
    FILE_DOWNLOAD_SUCCESS("file.download.success"),
    FILE_DOWNLOAD_FAILURE("file.download.failure"),
    FILE_DOWNLOAD_NOT_FOUND("file.download.not_found"),
    FILE_DOWNLOAD_NO_PERMISSION("file.download.no_permission"),
    FILE_DOWNLOAD_EXPIRED("file.download.expired"),
    FILE_DOWNLOAD_TOO_MANY("file.download.too_many"),

    // 文件操作
    FILE_OPERATE_DELETE_SUCCESS("file.operate.delete_success"),
    FILE_OPERATE_DELETE_FAIL("file.operate.delete_fail"),
    FILE_OPERATE_RENAME_SUCCESS("file.operate.rename_success"),
    FILE_OPERATE_RENAME_FAIL("file.operate.rename_fail"),
    FILE_OPERATE_MOVE_SUCCESS("file.operate.move_success"),
    FILE_OPERATE_MOVE_FAIL("file.operate.move_fail"),
    FILE_OPERATE_COPY_SUCCESS("file.operate.copy_success"),
    FILE_OPERATE_COPY_FAIL("file.operate.copy_fail"),

    // 文件处理
    FILE_PROCESS_SUCCESS("file.process.success"),
    FILE_PROCESS_FAILURE("file.process.failure"),
    FILE_PROCESS_PROCESSING("file.process.processing"),
    FILE_PROCESS_QUEUE("file.process.queue"),
    FILE_PROCESS_FORMAT_ERROR("file.process.format_error"),
    FILE_PROCESS_FILE_DAMAGE("file.process.file_damage"),
    FILE_PROCESS_SIGNATURE_MISMATCH("file.process.signature_mismatch"),

    // 文件夹相关
    FILE_FOLDER_CREATE_SUCCESS("file.folder.create_success"),
    FILE_FOLDER_CREATE_FAIL("file.folder.create_fail"),
    FILE_FOLDER_DELETE_SUCCESS("file.folder.delete_success"),
    FILE_FOLDER_DELETE_FAIL("file.folder.delete_fail"),
    FILE_FOLDER_NOT_FOUND("file.folder.not_found");


    /** 消息Code（与YAML文件中的键对应） */
    private final String code;

    MessageEnum(@NonNull String code) {
        this.code = code;
    }

    // 获取消息（依赖common模块的MessageSource）
    public String getMessage(MessageSource messageSource) {
        return messageSource.getMessage(code, null, LocaleContextHolder.getLocale());
    }

    // 带参数的消息（如"参数[{0}]不能为空"）
    public String getMessage(MessageSource messageSource, Object... args) {
        return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
    }
}